<template>
	<view>
		<view class="anchor-box" v-for="(item ,index) in list" :key="index" @click="toDetail(item.product_code)">
			<view class="user-box">
				<view class="head-img">
					<u--image :src="item.profile" v-if="item.profile" shape="circle" width="100rpx" height="100rpx">
						<template v-slot:loading>
							<u-loading-icon color="#a5a5a5" size="20"></u-loading-icon>
						</template>
					</u--image>
					<!-- <image :src="item.profile" v-if="item.profile"></image> -->
					<image :src="localIconSrc('17.png')" v-else></image>
					<view class="vip" v-if="item.cost_type">{{item.cost_type.val==0?'免费':item.cost_type.val}}</view>
				</view>
				<view class="name-box">
					<view class="name"><text class="te">{{item.name}}</text>
					<view class="language">{{ item.language.text }}</view>
						<!-- <image :src="localIconSrc('fire.png')"></image>  <text class="num">{{item.play_number}}</text> -->
					</view>
					<view class="user-remark">{{item.describe || ''}}</view>
				</view>
				<view class="btn">
					<view @click.stop="collectFun(item,index)" v-if="item.is_collect==1"><u-icon name="star-fill"
							color="#FF6005" size="26" style="margin-left: 20rpx;"></u-icon></view>
					<view @click.stop="collectFun(item,index)" v-else><u-icon name="star" color="#878787" size="26"
							style="margin-left: 20rpx;"></u-icon></view>
				</view>
			</view>
			<!-- 	<view class="user-status">
				<view class="item" v-for="item in 10">
					<view class="icon">生</view>
					<view class="remark">生气</view>
				</view>
			</view> -->
			<view class="type-box">
				<!-- <view class="item" @click.stop="ableType(items.id)" v-for="items in item.category" :key="items.id">
					{{items.name}}</view> -->
					<view class="item" v-for="items in item.label" :key="items.id">
						{{items}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		addCollect,
		cancelCollect
	} from '@/api/index.js'
	export default {
		name: "PubList",
		props: ['list'],
		data() {
			return {

			};
		},
		methods: {
			ableType(id) {
				this.$emit('typeClick', id)
			},
			collectFun(item, index) {
				if (!uni.getStorageSync('apiticket')) {
					uni.showModal({
						title: "提示",
						content: "请登录",
						success(res) {
							if (res.confirm) {
								setTimeout(() => {
									uni.navigateTo({
										url: "/pages/login/index",
									})
								}, 1000);
							}
						},
					});
					return
				}

				if (item.is_collect == 1) {
					let param = {
						productid: item.product_code //	String	是	32	产品ID或者产品代码
					}
					cancelCollect(param).then(res => {
						this.$emit('collectFun', index)
					})
				} else {
					let param = {
						type: 1, //	Int	是	3	产品类型:1 配音	
						productid: item.product_code //	String	是	32	产品ID或者产品代码
					}
					addCollect(param).then(res => {
						this.$emit('collectFun', index)
					})
				}

			},
			toDetail(code) {
				if (uni.getStorageSync('apiticket')) {
					uni.navigateTo({
						url: '/pages/ai-dub/detail/detail?code=' + code
					})
				} else {
					uni.showModal({
						title: "提示",
						content: "请登录",
						success(res) {
							if (res.confirm) {
								setTimeout(() => {
									uni.navigateTo({
										url: "/pages/login/index",
									})
								}, 1000);
							}
						},
					});
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.anchor-box {
		width: 92%;
		background-color: #fff;
		margin: auto;
		border-radius: 10rpx;
		margin-top: 20rpx;
		padding: 20rpx 20rpx;
		box-sizing: border-box;

		.user-box {
			display: flex;
			position: relative;
			padding-bottom: 36rpx;
			box-sizing: border-box;
			border-bottom: 1px solid #f4f4f4;

			.head-img {
				width: 100rpx;
				height: 100rpx;
				position: relative;

				.vip {
					position: absolute;
					bottom: -14rpx;
					left: 50%;
					transform: translateX(-50%);
					font-size: 20rpx;
					background-color: rgba(0, 0, 0, 0.6);
					color: #fff;
					height: 34rpx;
					width: 70rpx;
					border-radius: 30rpx;
					line-height: 34rpx;
					text-align: center;
				}

				image {
					height: 100%;
					width: 100%;
					border-radius: 50%;
				}

			}

			.name-box {
				margin-left: 20rpx;
				position: relative;

				.name {
					display: flex;
					align-items: center;
					font-size: 32rpx;
					color: #333;

					image {
						height: 34rpx;
						width: 34rpx;
						margin-left: 20rpx;
					}

					.te {
						max-width: 340rpx;
						white-space: nowrap;
						overflow-x: hidden;
						text-overflow: ellipsis;
					}

					.num {
						font-weight: 500;
						color: #999;
						margin-left: 10rpx;
					}
				}

				.user-remark {
					font-size: 24rpx;
					color: #999;
					margin-top: 20rpx;
				}
				
				.language {
					border: 1px solid #999;
					padding: 1px 4px;
					box-sizing: border-box;
					font-size: 20rpx;
					border-radius: 10rpx;
					margin-left: 20rpx;
					color: #999;
				}
			}

			.btn {
				position: absolute;
				right: 0rpx;
				top: -10rpx;
				font-size: 24rpx;
				padding: 6rpx 10rpx;
				box-sizing: border-box;

			}
		}

		.user-status {
			display: flex;
			overflow-x: scroll;
			margin-top: 20rpx;

			.item {
				width: 60rpx;
				margin-right: 20rpx;
				flex-shrink: 0;

				.icon {
					background-color: red;
					height: 60rpx;
					width: 60rpx;
					border-radius: 50%;
					text-align: center;
					line-height: 60rpx;
					color: #fff;
					font-size: 24rpx;
				}

				.remark {
					font-size: 24rpx;
				}
			}
		}

		.type-box {
			display: flex;
			margin-top: 20rpx;
			overflow-x: scroll;

			.item {
				color: #666;
				border-radius: 10rpx;
				background-color: #fff0e7;
				margin-right: 20rpx;
				flex-shrink: 0;
				padding: 6rpx 20rpx;
				box-sizing: border-box;
				// border-radius: 30rpx;
				border-radius: 8rpx;
				font-size: 24rpx;
			}
		}
	}
</style>